package com.netty;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

/**
 * @author CHL
 * @ClassName: FetchRegistryInfosHandler
 * @Description: 从注册中心拉取数据
 * @date 2022/12/30 16:26
 * @Version 1.0
 */
public class FetchRegistryInfosHandler extends SimpleChannelInboundHandler<RegistryInfo> {

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        ctx.channel().writeAndFlush("fetch registry infos");
    }

    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, RegistryInfo registryInfo) throws Exception {
        System.out.println("sender读取到注册信息：" + registryInfo);
        SenderClient
                .consumerHost = registryInfo.getHost();
        SenderClient.consumerPort = registryInfo.getPort();

        channelHandlerContext.channel().close();
    }
}
